﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Framework.Kit;
using System.Collections;
using BLL.Model;
using BLL.Service;

namespace BLL.Action
{
    public class teminal
    {
        teminalService tem = new teminalService();
        teminalModel temM = new teminalModel();
        XmlHelper xml = new XmlHelper();
        string file = "";

        public teminal()
        {
            file = other.CheckExists("teminal.xml", true, "Teminal");
        }

        /// <summary>
        /// 更新本地服务器终端表,提供客户端座位号检索
        /// </summary>
        public void UptTeminal()
        {
            foreach (teminalModel model in tem.SelectAll())
            {
                Hashtable htAttributes = new Hashtable();
                Hashtable htSubNodes = new Hashtable();
                htAttributes.Add("IP", model.Ip);
                htAttributes.Add("Num", model.Seatnumber);
                xml.InsertNode(file, "Node", true, "Teminal", htAttributes, htSubNodes);
            }
        }

        /// <summary>
        /// 返回客户端座位号,
        /// </summary>
        /// <param name="ip">检索IP</param>
        /// <returns></returns>
        public string GetSeatNum(string ip)
        {
            try
            {
                return XmlHelper.Read(file, "/Teminal/Node[@IP='" + ip + "']", "Num");
            }
            catch (Exception ex)
            {
                other.WriteErrLog("获取客户端座位号", ex);
                return null;
            }
        }
    }
}
